 
<fieldset class="layui-elem-field layui-form">
    <legend>搜索</legend>
    <div class="layui-field-box">
        <div class="layui-inline">
            <input class="layui-input" name="KeyWords" autocomplete="off" placeholder="名称" layui-type="search">
        </div> 
        <button class="layui-btn" data-type="search" id="btnSearch">搜索</button>
    </div>
</fieldset>
<script type="text/html" id="toolbarList">
    <div class="layui-btn-container">
        @Html.Raw(ViewBag.ButtonHtml)
    </div>
</script> 
<script type="text/html" id="isTop">
    <input type="checkbox" name="isTop" value="{{d.isTop}}" disabled lay-skin="switch" lay-text="是|否" {{ d.isTop ? 'checked' : '' }}>
</script>
<table class="layui-hide" lay-filter="tblList" id="tblList"></table>
@section Scripts{
    <script type="text/javascript">
        var pageIndex = 1;
        layui.use('table', function () {
            var $ = layui.$, table = layui.table;
            var tblList = table.render({
                elem: '#tblList'
                , url: '/Admin/Adv/GetList' + getSearchKeys()
                , toolbar: '#toolbarList'
                , defaultToolbar: ['filter', 'print']//['filter', 'print', 'exports']
                , cellMinWidth: 100
                , page: {
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']  //自定义分页布局
                    , curr: 1                                                   //当前页码
                    , groups: 9                                                //显示页码数
                    , first: false                                              //不显示首页
                    , last: false                                               //不显示尾页
                }
                , cols: [[
                    { type: 'checkbox' },
                    { field: 'advName', title: '广告名称' },
                    { field: 'advImg', title: '广告图片', templet: function (d) { return '<img src="' + d.advImg +'" style="height:80px" />' } },
                    { field: 'posName', title: '广告位' }, 
                    { field: 'startTime', title: '开始时间' },
                    { field: 'endTime', title: '结束时间' }, 
                    { field: 'jmpUrl', title: '跳转Url' },
                    { field: 'createTime', title: '创建时间' } 
                ]]
            });
            //头工具栏事件
            table.on('toolbar(tblList)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                switch (obj.event) {
                    case 'add':
                        win.open("/Admin/Adv/AddEdit", 650, 550, "新增");
                        break;
                    case 'edit':
                        if (data != "") {
                            win.open("/Admin/Adv/AddEdit/" + data[0].id, 650, 550, "编辑");
                        } else {
                            win.info("请选择要编辑的内容");
                        }
                        break;
                    case 'del':
                        if (data != "") {
                            var guids = [];
                            $(data).each(function (i, item) {
                                guids.push(item.id);
                            });
                            win.confirm("确认要删除吗？", function () {
                                $.post("/Admin/Adv/Remove", { ids: guids }, function (res) {
                                    if (res.code == 0) {
                                        win.success("删除成功");
                                        getList();
                                    } else {
                                        win.alert(res.Message);
                                    }
                                });
                            });
                        } else {
                            win.info("请选择要删除的内容");
                        }
                        break;
                };
            });
            var active = {
                search: function () {
                    //执行搜索并重载用户
                    tblList.reload({
                        url: "/Admin/Adv/GetList" + getSearchKeys(),
                        page: {
                            layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']  //自定义分页布局
                            , curr: 1                                                   //当前页码
                            , groups: 9                                                 //显示页码数
                            , first: false                                              //不显示首页
                            , last: false                                               //不显示尾页
                        }
                    });
                }
            };
            //搜索按钮
            $('#btnSearch').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
}
	 
